package server

import (
	"net/http"
)

// Server 类
type Server struct {
	router *router
}

// New 实例化一个 Server 类
func New() *Server {
	return &Server{}
}

// ServeHTTP 实现 http.Handler 接口
func (server *Server) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	c := newContext(w, req)
	server.router.matchRoute(c)
}

// Run 返回 http.ListenAndServe 运行结果
func (server *Server) Run(addr string) (err error) {
	return http.ListenAndServe(addr, server)
}